package com.hourse.controller;

import com.hourse.pojo.*;
import com.hourse.service.HouseService;
import com.hourse.util.PageResult;
import com.hourse.util.PageUtil;
import com.hourse.util.Result;
import com.hourse.util.StatusCode;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("hourse")
@CrossOrigin
public class HouseController {

    @Autowired
    private HouseService houseService;
    @Autowired
    private HttpServletRequest request;


    @GetMapping
    public PageUtil<House> list(@RequestParam(value = "page",required = false,defaultValue = "1")Integer page,
                                             @RequestParam(value = "size",defaultValue = "10",required = false)Integer size){

        Page<House> plist=  houseService.findAll(page,size);
        return new PageUtil<House>(page,plist.getTotalElements(),plist.getContent(),size);


    }

//    @RequestMapping("/findPage")
//    public PageResult  findPage(int page,int rows){
//        return itemService.findPage(page, rows);
//    }


    @PostMapping("/houseAdd")
    public Result houseAdd(@RequestBody House house){
        String token = (String) request.getAttribute("claims_user");
        if (token==null||"".equals(token)){
            return new Result(false,StatusCode.OK,"权限不足");
        }
        houseService.houseAdd(house);

        return new Result(true,StatusCode.OK,"添加成功");
    }


    @PutMapping("/houseUp")
    public Result houseUp(@RequestBody House house){

        houseService.houseUp(house);

        return new Result(true,StatusCode.OK,"修改成功");
    }

    @DeleteMapping("/houseDelete")
    public Result houseDelete(Long id){

        houseService.houseDelete(id);

        return new Result(true,StatusCode.OK,"删除成功");
    }
    @RequestMapping(value = "/shen",method = RequestMethod.GET)
    public List<DgtxPlaces> shenlist(){
        return houseService.shenlist();
    }
    @RequestMapping(value = "/shen/cname/{id}",method = RequestMethod.GET)
    public DgtxPlaces shencname(@PathVariable Long id){
        return houseService.shencname(id);
    }
    @RequestMapping(value = "/shi/{id}",method = RequestMethod.GET)
    public List<DgtxPlaces> shicname(@PathVariable Long id){
        return houseService.shicname(id);
    }
    @RequestMapping(value = "/huxing/list",method = RequestMethod.GET)
    public List<HouseHuxing> huxinglist(){
        return houseService.huxinglist();
    }
    @RequestMapping(value = "/kaipan/list",method = RequestMethod.GET)
    public List<HouseKaipan> kaipanlist(){
        return houseService.kaipanlist();
    }
    @RequestMapping(value = "/status/list",method = RequestMethod.GET)
    public List<HouseStatus> statuslist(){
        return houseService.statuslist();
    }
    @RequestMapping(value = "/test/list",method = RequestMethod.GET)
    public List<HouseTese> teselist(){
        return houseService.teselist();
    }
    @RequestMapping(value = "/wuye/list",method = RequestMethod.GET)
    public List<HouseWuye> wuyelist(){
        return houseService.wuyelist();
    }
    @RequestMapping(value = "/zhuangxiu/list",method = RequestMethod.GET)
    public List<HouseZhuangxiu> zhuangxiulist(){
        return houseService.zhuangixulist();
    }
}
